package com.sqbang.dbcompare.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

/**
 * 静态资源路径配置
 */
@Component
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    PathConfig pathConfig;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String outPath = System.getProperty("user.dir") + File.separator + pathConfig.getTemplateDiskDir() + File.separator;
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler(String.format("/%s/**", pathConfig.getTemplateDiskDir())).addResourceLocations("file:" + outPath);
    }
}